package com.zatech.cgnci.project.controller.claim;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zatech.cgnci.project.base.enums.ClaimSettlementTypeEnum;
import com.zatech.cgnci.project.dto.CgnciClaimCaseQueryDTO;
import com.zatech.cgnci.project.dto.SettlementQueryDTO;
import com.zatech.cgnci.project.service.CgnciClaimCaseService;
import com.zatech.cgnci.project.service.CgnciClaimSettlementService;
import com.zatech.cgnci.project.vo.CgnciClaimCasePageVO;
import com.zatech.cgnci.project.vo.CgnciClaimCaseVO;
import com.zatech.cgnci.project.vo.CgnciClaimSettlementVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/claim/query")
@RequiredArgsConstructor
@Api(produces = "application/json", tags = "理赔查询")
public class CgnciClaimQueryController {
    private final CgnciClaimCaseService cgnciClaimCaseService;
    private final CgnciClaimSettlementService claimSettlementService;

    @GetMapping("/caseDetail")
    @ApiOperation(value = "查询案件详情")
    public CgnciClaimCaseVO caseDetail(@RequestParam("caseNo") String caseNo) {
        Assert.notNull(caseNo,"案件号必填.");
        return cgnciClaimCaseService.detail(caseNo);
    }

    @PostMapping("/settlementQuery")
    @ApiOperation(value = "结算详情")
    public CgnciClaimSettlementVO settlementQuery(@RequestBody SettlementQueryDTO req) {
        Assert.hasText(req.getCaseNo(),"案件号必填。");
        Assert.hasText(req.getSettlementNo(),"结案号必填。");
        ClaimSettlementTypeEnum typeEnum = ClaimSettlementTypeEnum.getEnumByCode(req.getSettlementType());
        Assert.notNull(typeEnum,"结算类型错误。");
        return claimSettlementService.settlementQuery(req);
    }


    @PostMapping("/casePage")
    @ApiOperation(value = "案件分页查询")
    public IPage<CgnciClaimCasePageVO> casePage(@RequestBody CgnciClaimCaseQueryDTO req) {
        return cgnciClaimCaseService.pageClaimCase(req);
    }
}
